using System;
using System.Collections.Generic;
using System.Text;
using Decav.Gatsb.Application;
using System.Text.RegularExpressions;

namespace Decav.Gatsb
{
    /// <summary>
    /// Defines the search criteria used to find a <see cref="Location"/>.
    /// </summary>
    [Serializable]
    public class LocationSearchCriteria
    {
        public LocationSearchCriteria(string searchString, string postalCode)
        {
            _searchString = searchString;
            _postalCode = postalCode;
        }

        private string _searchString;
        private string _postalCode;
        private string _city;
        private string _state;
        private LocationType _type = LocationType.Unknown;

        /// <summary>
        /// Gets or sets the search string to search for.
        /// </summary>
        public string SearchString
        {
            get
            {
                return _searchString;
            }
            set
            {
                _searchString = value;
            }
        }

        /// <summary>
        /// Gets or sets the postal code to search around.
        /// </summary>
        public string PostalCode
        {
            get
            {
                return _postalCode;
            }
            set
            {
                _postalCode = value;
            }
        }

        /// <summary>
        /// Gets or sets the optional city to search within.
        /// </summary>
        public string City
        {
            get
            {
                return _city;
            }
            set
            {
                _city = value;
            }
        }

        /// <summary>
        /// Gets or sets the optional state to search within.
        /// </summary>
        public string State
        {
            get
            {
                return _state;
            }
            set
            {
                _state = value;
            }
        }

        /// <summary>
        /// Gets or sets the specific type of location being searched for.
        /// </summary>
        public LocationType Type
        {
            get
            {
                return _type;
            }
            set
            {
                _type = value;
            }
        }

        /// <summary>
        /// Parses textual input of a location to find into search criteria.
        /// </summary>
        /// <param name="searchString">The search to conduct.</param>
        /// <returns>The search criteria defined by the search string.</returns>
        public static LocationSearchCriteria Parse(string searchString)
        {
            if (searchString == null)
                throw new ArgumentNullException("searchString");

            return GatsbApplication.Current.CurrentLocale.ParseSearchString(searchString);
        }
    }
}
